#Requires AutoHotkey v2.0

class MyToolBar {
  static btnW := MyButton.btnW
  static btnH := MyButton.btnH

  __New(btnCount, nameList, startX, startY, CallBackList, btnW := unset, btnH := unset) {
    this.btnCount := btnCount
    this.nameList := nameList
    this.startX := startX
    this.startY := startY
    this.CallBackList := CallBackList
    IsSet(btnW) && MyButton.btnW := btnW
    IsSet(btnH) && MyButton.btnH := btnH
  }

  static SetWH(w, h) {
    MyButton.btnW := w
    MyButton.btnH := h
  }

  Modefiy(index, text) {
    this.btnList[index].Text := text
  }

  Show() {
    btnList := Array()
    loop this.btnCount {
      btnList.Push(MyButton.Show(this.nameList[A_Index]
        , this.startX + (A_Index - 1) * MyButton.btnW
        , this.startY, this.CallBackList[A_Index]))
    }
    this.btnList := btnList
  }

  Hide() {
    for v in this.btnList
      v.Hide()
  }

  Move(nx, ny) {
    loop this.btnCount {
      this.btnList[A_Index].Move(nx + MyToolBar.btnW * (A_Index - 1), ny)
    }
  }

  Destroy() {
    loop this.btnCount
      this.btnList[A_Index].Destroy()
  }
}

Class MyButton extends Gui {
  static btnW := 70
  static btnH := 35

  __New(value) {
    super.__New('+AlwaysOnTop -Caption +ToolWindow')
    this.SetFont('s14')
    this.ins := this.AddButton('xs w' MyButton.btnW ' h' MyButton.btnH, value)
    this.Show('w' MyButton.btnW ' h' MyButton.btnH)
  }

  static Show(value, x, y, Action) {
    g := MyButton(value)
    g.ins.OnEvent('Click', (*) => this.OnClickConfirm(g, Action))
    g.Show('x' x ' y' y)
    return g
  }

  static OnClickConfirm(ins, Callback) {
    Callback(ins)
  }
}

if A_LineFile == A_ScriptFullPath {

  CB1(btn) {
    MsgBox btn.ins.Text
  }
  CB2(btn) {
    MsgBox 'cb2'
  }
  t := MyToolBar(2, ['Ok', 'Cancel'], 960, 540, [CB1, CB2])
  t.Show()
  ; t.Move(0, 0)
  ; t.Destroy()
}